<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<title>致一年未见的你</title>
	<link rel="stylesheet" href="css/common.css">
	<link rel="stylesheet" href="css/loadding.css">
<!-- <!-- 	<style type="text/css"> --> 
<!-- /* 		.next-btn{ */ -->
<!-- /* 			display: block; */ -->
<!-- /* 			width: 210px; */ -->
<!-- /* 			height: 35px; */ -->
<!-- /* 			line-height: 35px; */ -->
<!-- /* 			margin:0 auto; */ -->
<!-- /* 			background: #1fbad6; */ -->
<!-- /* 			border-radius: 5px; */ -->
<!-- /* 			color:#fff; */ -->
<!-- /* 			text-align: center; */ -->
<!-- /* 			position: absolute; */ -->
<!-- /* 			bottom:-10px; */ -->
<!-- /* 			left: 50%; */ -->
<!-- /* 			right:50%; */ -->
<!-- /* 			transform: translate(-50%, -50%); */ -->
<!-- /* 			-webkit-box-shadow:0 2px 0 #049fb3; */ -->
<!-- /* 		} */ -->
<!-- <!-- 	</style> --> 
<style type="text/css">
		.form-control{width:100px;border:none;border-bottom:1px solid #ccc;color:#b7b8b8}
		.next-btn1{
			width:40%;
			height: 35px;
    		line-height: 35px;
			display: inline-block;
			text-align: center;
			background: #1fbad6;
			border-radius: 5px;
			color:#fff;
			-webkit-box-shadow:0 2px 0 #049fb3;
		}
		.next-btn1:first-child{
			margin-right: 20px;
		}
		.btn-group{
			position: absolute;
		    bottom: -10px;
		    left: 50%;
		    right: 50%;
    		transform: translate(-50%, -50%);
			width: 80%;
		    text-align: center;
		    color: #fff;
		    margin-top: 20px;
		}
	</style>
</head>

<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/notReturnFactorCommon.js"></script>
<script type="text/javascript" src="../../../js/common/common.js"></script>
<script type="text/javascript" src="../../../js/common/wechatCommon.js"></script>
<script>

	var rootPath = getRootPath();
	
	$(function(){
		showLoadding();
		$.ajax({
			headers:{'Cookie':document.cookie},
			type:"POST", 
// 	        url:"http://127.0.0.1:9013/pointActivity/api/v1/queryQuestion",
	        url:rootPath + "/pointActivity/api/v1/queryQuestion",
	        dataType:"json",
	        contentType:"application/json",
	        success:function(data){
	        	console.log(data);
	        	hideLoadding();
	        	if(data.qtnTitle != null){
	        		$(".title").html(data.qtnNo+"."+data.qtnTitle);
	        		var insertHtml = "";
	        		for(var i = data.list.length - 1; i >= 0; i--){
	        			if(data.qtId == 1){
	        				insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
		        		}
		        		else if(data.qtId == 2){
		        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
		        				insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"<input type='text' class='form-control paddY-5 paddL-10' value='请填写其他内容！'></span></p>";
	        				}else{
	        					insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        				}
		        		}
		        		else{
		        			insertHtml = "<p class='padd-10'><textarea class='wid-90 padd-5' style='background: #fff' cols='30' rows='10'></textarea></p>";
		        		}
	        			$('.contentwrap').find('p').eq(0).after(insertHtml);
	        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
	        				$('.form-control').focus(function(){
	        					var $textval = $(this).val();
	        					if($textval == "请填写其他内容！"){
	        						$(this).val("");
	        					}
	        				})
	        				$('.form-control').blur(function(){
	        					var $textval = $(this).val();
	        					if($textval == ""){
	        						$(this).val('请填写其他内容！');
	        					}
	        				})
	        			}
	        		}
	        		if(data.qtId == 1){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        				}else{
	        					$this.addClass('on_check');
	        				}
	        			})
	        		}
	        		else if(data.qtId == 2){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        				}else{
	        					$this.addClass('on_check').parent().siblings().children('.acheck').removeClass('on_check');
	        				}
	        			})
	        		}
	        		if(data.qtnNo != 1){
	        			insertHtml = "<a class='next-btn1' onclick='toLast("+JSON.stringify(data)+")'>上一题</a>";
	        			$('.btn-group').append(insertHtml);
	        		}
	        		if(data.qtnNo ==2 || data.qtnNo == 12){
	        			insertHtml = "<a class='next-btn1' onclick='toNext("+JSON.stringify(data)+")'>提交问卷</a>";
	        		}
	        		else{
	        			insertHtml = "<a class='next-btn1' onclick='toNext("+JSON.stringify(data)+")'>下一题</a>";
	        		}
	        		$('.btn-group').append(insertHtml);
	        	}
	        	else{
	        		if(data.qtnNo == 2){
// 	        			window.location.href = rootPath + "/views/gmmcActivity/NotReturnFactory/extract-2.html?random=" + parseInt(10000 * Math.random())";
	        			window.location.replace(rootPath + "/views/gmmcActivity/NotReturnFactory/extract-2.html?random=" + parseInt(10000 * Math.random()));	
	        		}
	        		else if(data.qtnNo == 12){
// 	        			window.location.href = rootPath + "/views/gmmcActivity/NotReturnFactory/extract.html?random=" + parseInt(10000 * Math.random())";
	        			window.location.replace(rootPath + "/views/gmmcActivity/NotReturnFactory/extract.html?random=" + parseInt(10000 * Math.random()));	
	        		}
	        		else if(data.qtnNo == 0){
	        			showAlert("您已完成答题！");
	        			return;
	        		}
	        		else{
	        			showAlert("提交数据失败！");
	        			return;
	        		}
	        	}
	        }
	     });
		
	});
	
	
	function toLast(data){
		showLoadding();
		$.ajax({
			headers:{'Cookie':document.cookie},
			type:"POST", 
// 	        url:"http://127.0.0.1:9013/pointActivity/api/v1/queryLastQuestionByQtnNo?qtnNo="+data.qtnNo+"&qId="+data.qId+"&ownerId="+data.ownerId+"&qtnId="+data.qtnId+"&qneId="+data.qneId,
			url:rootPath + "/pointActivity/api/v1/queryLastQuestionByQtnNo?qtnNo="+data.qtnNo+"&qId="+data.qId+"&ownerId="+data.ownerId+"&qtnId="+data.qtnId+"&qneId="+data.qneId,
	        dataType:"json",
	        contentType:"application/json",
	        beforeSend: function(){    
	        	 $(".next-btn1").unbind(); //取消事件
	        	},
	        success:function(data){
// 	        	$("p").remove(".padd-10");
// 	    		$(".btn-group").empty();
	        	hideLoadding();
	        	if(data.qtnTitle != null){
	        		$("p").remove(".padd-10");
		    		$(".btn-group").empty();
	        		$(".title").html(data.qtnNo+"."+data.qtnTitle);
	        		var str = "";
	        		var insertHtml = "";
	        		for(var i = data.list.length - 1; i >= 0; i--){
	        			if(data.qtId == 1){
	        				if(data.userAnswer != null && data.userAnswer != ""){
	        					str = data.userAnswer;
	        				}
	        				if(isContains(str,data.list[i].answerId)){
	        					insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        				}else{
	        					insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        				}
		        		}
		        		else if(data.qtId == 2){
		        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
		        				if(data.list[i].answerId == data.remark){
		        					insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"<input type='text' class='form-control paddY-5 paddL-10' value='"+data.userAnswer+"'></span></p>";
		        				}else{
		        					insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"<input type='text' class='form-control paddY-5 paddL-10' value='请填写其他内容！'></span></p>";
		        				}
	        				}else{
	        					if(data.list[i].answerId == data.remark){
	        						insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        					}else{
	        						insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        					}
	        				}
		        		}
		        		else{
		        			insertHtml = "<p class='padd-10'><textarea class='wid-90 padd-5' style='background: #fff' cols='30' rows='10'></textarea></p>";
		        		}
	        			$('.contentwrap').find('p').eq(0).after(insertHtml);
	        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
	        				$('.form-control').focus(function(){
	        					var $textval = $(this).val();
	        					if($textval == "请填写其他内容！"){
	        						$(this).val("");
	        					}
	        				});
	        				$('.form-control').blur(function(){
	        					var $textval = $(this).val();
	        					if($textval == ""){
	        						$(this).val('请填写其他内容！');
	        					}
	        				});
	        			}
	        		}
	        		if(data.qtId == 1){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        				}else{
	        					$this.addClass('on_check');
	        				}
	        			})
	        		}
	        		else if(data.qtId == 2){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        				}else{
	        					$this.addClass('on_check').parent().siblings().children('.acheck').removeClass('on_check');
	        				}
	        			})
	        		}
	        		
	        		if(data.qtnNo != 1){
	        			insertHtml = "<a class='next-btn1' onclick='toLast("+JSON.stringify(data)+")'>上一题</a>";
	        			$('.btn-group').append(insertHtml);
	        		}
	        		insertHtml = "<a class='next-btn1' onclick='toNext("+JSON.stringify(data)+")'>下一题</a>";
	        		$('.btn-group').append(insertHtml);
	        	}
	        	else{
	        		if(data.qtnNo == 0){
	        			showAlert("您已完成答题！");
	        			return;
	        		}
	        	}
	        },
	        complete: function(){
        		$(".next-btn1").bind();  //绑定事件
        		}
	        
	     });
	}
	
	function toNext(data){
		console.log(data);
		var answer = "";
		var url = "";
		var answerId = "";
		if(data.qtId == 2){
			var $this = $('.acheck.on_check');
			if($this.length > 0){
				answerId = $('.acheck.on_check')[0].id;
				answer = $('.acheck.on_check')[0].id;
				if(answerId != null && answerId != ""){
					var answerTitle = $('.acheck.on_check').next()[0].innerText;
	    			if(answerTitle == "D、其他" || answerTitle == "F、其他"){
	    				answer = $.trim($('.form-control').val());
	    			}
	    			if(answer == null || answer == "" || answer =="请填写其他内容！"){
		    			showAlert("您还没填写任何内容！");
	    				return;
	    			}
	    			if(answer.length > 20){
	    				showAlert("最多输入20个字！");
	    				return;
	    			}
	    			console.log(answer);
// 					url = "http://127.0.0.1:9013/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&answer="+answer+"&qneId="+data.qneId+"&qId="+data.qId+"&ownerId="+data.ownerId+"&answerId="+answerId;
					url = rootPath + "/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&answer="+answer+"&qneId="+data.qneId+"&qId="+data.qId+"&ownerId="+data.ownerId+"&answerId="+answerId;
					goNext(data,url);
					}
			}else{
				showAlert("您还没选中任何内容！");
				return;
			}
		}
		else if(data.qtId ==1){
			var answerArr =[]; 
			var $this = $('.acheck.on_check');
			console.log($this);
			$('.acheck.on_check').each(function(){
				answerArr.push($(this).context.id); 
			}); 
			console.log(answerArr);
			if(answerArr.length == 0){
				showAlert("您还没选中任何内容！");
				return;
			}
			else if(answerArr.length > 3){
				showAlert("最多选择三项！");
				return;
			}
			else{
				for(var i = 0; i < answerArr.length; i++){
					answer = answer + answerArr[i] +",";
					}
				answer = answer.substring(0,answer.length-1);
// 				url = "http://127.0.0.1:9013/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&qneId="+data.qneId+"&answer="+answer+"&qId="+data.qId+"&ownerId="+data.ownerId;
				url = rootPath + "/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&qneId="+data.qneId+"&answer="+answer+"&qId="+data.qId+"&ownerId="+data.ownerId;
				goNext(data,url);	
				}
			}
		else{
			answer = $.trim($('textarea').val());
			if(answer == null || answer == "" || answer =="请填写其他内容！"){
				showAlert("您还没填写任何内容！");
				return;
			}
			if(answer.length > 100){
				showAlert("最多输入100个字！");
				return;
			}
			else{
// 				url = "http://127.0.0.1:9013/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&qneId="+data.qneId+"&answer="+answer+"&qId="+data.qId+"&ownerId="+data.ownerId;
				url = rootPath + "/pointActivity/api/v1/queryNextQuestionByQtnNo?qtnNo="+data.qtnNo+"&qtnId="+data.qtnId+"&qneId="+data.qneId+"&answer="+answer+"&qId="+data.qId+"&ownerId="+data.ownerId;
				goNext(data,url);
			}
		}
	}
	
	function goNext(data,url){
		showLoadding();
		console.log(data);
		console.log(url);
		$.ajax({
			headers:{'Cookie':document.cookie},
			type:"POST", 
	        url:url,
	        dataType:"json",
	        contentType:"application/json",
	        beforeSend: function(){    
	        	 $(".next-btn1").unbind(); //取消事件
	        	},
	        success:function(data){
	        	console.log(data);
// 	        	$("p").remove(".padd-10");
// 	    		$(".btn-group").empty();
	        	hideLoadding();
	        	if(data.qtnTitle != null){
	        		$("p").remove(".padd-10");
		    		$(".btn-group").empty();
	        		$(".title").html(data.qtnNo+"."+data.qtnTitle);
	        		var str = "";
	        		var insertHtml = "";
	        		for(var i = data.list.length - 1; i >= 0; i--){
	        			if(data.qtId == 1){
	        				if(data.userAnswer != null && data.userAnswer != ""){
	        					str = data.userAnswer;
	        				}
	        				if(isContains(str,data.list[i].answerId)){
	        					insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        				}else{
	        					insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        				}
		        		}
		        		else if(data.qtId == 2){
		        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
		        				if(data.list[i].answerId == data.remark){
		        					insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"<input type='text' class='form-control paddY-5 paddL-10' value='"+data.userAnswer+"'></span></p>";
		        				}else{
		        					insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"<input type='text' class='form-control paddY-5 paddL-10' value='请填写其他内容！'></span></p>";
		        				}
	        				}else{
	        					if(data.list[i].answerId == data.remark){
	        						insertHtml = "<p class='padd-10'><span class='acheck on_check' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        					}else{
	        						insertHtml = "<p class='padd-10'><span class='acheck' id='"+data.list[i].answerId+"'></span><span class='inline-block ver-middle'>"+data.list[i].answer+"</span></p>";
	        					}
	        				}
		        		}
		        		else{
		        			insertHtml = "<p class='padd-10'><textarea class='wid-90 padd-5' style='background: #fff' cols='30' rows='10'></textarea></p>";
		        		}
	        			$('.contentwrap').find('p').eq(0).after(insertHtml);
	        			if(data.list[i].answer == "D、其他" || data.list[i].answer == "F、其他"){
	        				$('.form-control').focus(function(){
	        					var $textval = $(this).val();
	        					if($textval == "请填写其他内容！"){
	        						$(this).val("");
	        					}
	        				})
	        				$('.form-control').blur(function(){
	        					var $textval = $(this).val();
	        					if($textval == ""){
	        						$(this).val('请填写其他内容！');
	        					}
	        				})
	        			}
	        		}
	        		if(data.qtId == 1){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        				}
	        				else{
	        					$this.addClass('on_check');
	        				}
	        			})
	        		}
	        		else if(data.qtId == 2){
	        			$('.acheck').on('click',function(){
	        				var $this = $(this);
	        				if($this.context.className == "acheck on_check"){
	        					$this.context.className = "acheck";
	        					}
	        				else{
	        					$this.addClass('on_check').parent().siblings().children('.acheck').removeClass('on_check');
	        					}
	        				});
	        			}
	        		if(data.qtnNo != 1){
	        			insertHtml = "<a class='next-btn1' onclick='toLast("+JSON.stringify(data)+")'>上一题</a>";
	        			$('.btn-group').append(insertHtml);
	        			}
	        		if(data.qtnNo ==2 || data.qtnNo == 12){
	        			insertHtml = "<a class='next-btn1' onclick='toNext("+JSON.stringify(data)+")'>提交问卷</a>";
	        			}
	        		else{
	        			insertHtml = "<a class='next-btn1' onclick='toNext("+JSON.stringify(data)+")'>下一题</a>";
	        			}
	        		$('.btn-group').append(insertHtml);
	        	}
	        	else{
	        		if(data.qtnNo == 2){
// 	        			window.location.href = rootPath + "/views/gmmcActivity/NotReturnFactory/extract-2.html?random=" + parseInt(10000 * Math.random())";
	        			window.location.replace(rootPath + "/views/gmmcActivity/NotReturnFactory/extract-2.html?random=" + parseInt(10000 * Math.random()));
	        			}
	        		else if(data.qtnNo == 12){
// 	        			window.location.href = rootPath + "/views/gmmcActivity/NotReturnFactory/extract.html?random=" + parseInt(10000 * Math.random())";
	        			window.location.replace(rootPath + "/views/gmmcActivity/NotReturnFactory/extract.html?random=" + parseInt(10000 * Math.random()));
	        			//window.location.href = "extract.html";
	        			}
	        		else if(data.qtnNo == 0){
	        			showAlert("您已完成答题！");
	        			return;
	        			}
	        		else{
	        			showAlert("提交数据失败！");
	        			return;
	        			}
	        		}
	        	},
	        	complete: function(){
	        		$(".next-btn1").bind();  //绑定事件
	        		}
			});
		}
	
	function isContains(str, substr) {
	    return str.indexOf(substr) >= 0;
	}
	
</script>



<body>
	<div class="por">
		<div class="contentwrap">
			<p class="title"></p>
<!-- 			<p class="padd-10"> -->
<!-- 				<span class="acheck"></span><span class="inline-block ver-middle">A 是</span> -->
<!-- 			</p> -->
<!-- 			<p class="padd-10"> -->
<!-- 				<span class="acheck"></span><span class="inline-block ver-middle">B 否</span> -->
<!-- 			</p> -->
			<div class="btn-group">
<!-- 				<a class="next-btn1" href="answer-1.html">上一题</a> -->
<!-- 				<a class="next-btn1"  href="answer-3.html">下一题</a> -->
			</div>
		</div>
	</div>
	
</body>

</html>